import { createRouter, createWebHistory } from 'vue-router'
import homePage from '@/views/homePage.vue'
import mePage from '@/views/mePage.vue'
import createStep from '@/views/AIPoseStep.vue'
import myDiamonds from '@/views/myDiamonds.vue'
import supportCenter from '@/views/supportCenter.vue'
import feedback from '@/views/feedbackPage.vue'
import cookiePolicy from '@/views/cookiePolicy.vue'
import privacyPolicy from '@/views/privacyPolicy.vue'
import termsService from '@/views/termsService.vue'
import diamondsDetails from '@/views/diamondsDetails.vue'
import removeAll from '@/views/removeAll.vue'
import AIPose from '@/views/AIPose.vue'
import RemoveCreating from '@/views/removeCreating.vue'
import PoseCreating from '@/views/poseCreating.vue'
import RemovePose from '@/views/removePose.vue'
import RetryPage from '@/views/retryPage.vue'
import PurchaseSuccessful from '@/views/purchaseSuccessful.vue'
import PurchaseFailed from '@/views/purchaseFailed.vue'
import GoogleLogin from '@/views/googleLogin.vue'
import KeepBackView from '@/views/keepBack.vue'



const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'homePage',
      component: homePage,
    },
    {
      path: '/keepBack',
      name: 'KeepBack',
      component: KeepBackView,
    },
    {
      path: '/me',
      name: 'mePage',
      component: mePage,
    },
    {
      path: '/createStep',
      name: 'createStep',
      component: createStep,
    },
    {
      path: '/myDiamonds',
      name: 'myDiamonds',
      component: myDiamonds,
    },
    {
      path: '/supportCenter',
      name: 'supportCenter',
      component: supportCenter,
    },
    {
      path: '/feedback',
      name: 'feedback',
      component: feedback,
    },
    {
      path: '/cookiePolicy',
      name: 'cookiePolicy',
      component: cookiePolicy,
    },
    {
      path: '/privacyPolicy',
      name: 'privacyPolicy',
      component: privacyPolicy,
    },
    {
      path: '/termsService',
      name: 'termsService',
      component: termsService,
    },
    {
      path: '/diamondsDetails',
      name: 'diamondsDetails',
      component: diamondsDetails,
    },
    {
      path: '/removeAll',
      name: 'removeAll',
      component: removeAll,
      meta: { requireBackConfirm: true }
    },
    {
      path: '/removePose',
      name: 'RemovePose',
      component: RemovePose,
    },
    {
      path: '/AIPose',
      name: 'AIPose',
      component: AIPose,
    },
    {
      path: '/removeCreating',
      name: 'RemoveCreating',
      component: RemoveCreating,
    },
    {
      path: '/poseCreating',
      name: 'PoseCreating',
      component: PoseCreating,
    },
    {
      path: '/retryPage',
      name: 'RetryPage',
      component: RetryPage,
    },
    {
      path: '/purchaseSuccessful',
      name: 'PurchaseSuccessful',
      component: PurchaseSuccessful,
    },
    {
      path: '/purchaseFailed',
      name: 'PurchaseFailed',
      component: PurchaseFailed,
    },
    {
      path: '/googleLogin',
      name: 'GoogleLogin',
      component: GoogleLogin,
    }
    // {
    //   path: '/about',
    //   name: 'about',
    //   // route level code-splitting
    //   // this generates a separate chunk (About.[hash].js) for this route
    //   // which is lazy-loaded when the route is visited.
    //   component: () => import('../views/AboutView.vue'),
    // },
  ],
  scrollBehavior() {
    // 始终滚动到页面顶部
    return { top: 0 };
  }
})

// router/index.js 修改守卫
router.beforeEach((to, from, next) => {
  if (from.name) {
    const safeRoute = {
      fullPath: from.fullPath,
      path: from.path,
      query: from.query,
      params: from.params,
      name: from.name
    };
    sessionStorage.setItem('prevRoute', JSON.stringify(safeRoute));
  }
  next();
});


export default router
